import Vue from "vue";
import Vuex from "vuex";
import axios from "@/api";

import app from "./modules/app";
// 登录
// import user from "./modules/user";
// 免登录
// import user from "./modules/user-noauth";

// 静态路由
// import permission from "./modules/permission";
// 动态路由
// import permission from './modules/async-router'

import getters from "./getters";
import { reject } from "lodash";

Vue.use(Vuex);

export default new Vuex.Store({
  modules: {
    app
  },
  state: {
    companyInfo: {}
  },
  mutations: {
    setCompanyInfo(state, companyInfo) {
      state.companyInfo = companyInfo;
    }
  },
  actions: {
    getCompanyInfo({ commit }) {
      return new Promise((resolve, reject) => {
        axios
          .get("/companies/information")
          .then((res) => {
            if (res.success) {
              commit("setCompanyInfo", res.model);
            }
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    }
  },
  getters
});
